package org.jrpc.core.event;

import org.jrpc.client3.JrpcClientManage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * Created by chenyuncong on 2019/4/23.
 * 上下线事件管理
 */
@Component
public class EventHandlerRegistryAndDiscovery implements EventRegistryAndDiscovery {
    private static final Logger LOGGER = LoggerFactory.getLogger(EventHandlerRegistryAndDiscovery.class);

    @Autowired
    private JrpcClientManage jrpcClientManage;

    /**
     * 服务上线事件
     * @param event
     */
    @Async
    @EventListener
    @Override
    public void up(UpServiceEvent event) {
        System.out.println("DownServiceEvent"+event.getClass());
        LOGGER.info("up");
        //修改缓存，触发zk

    }

    /**
     * 服务下线事件
     * @param event
     */
    @Async
    @EventListener
    @Override
    public void down(DownServiceEvent event) {
        System.out.println("DownServiceEvent"+event.getClass());
        LOGGER.info("down");
    }

    /**
     * 注册事件
     * @param event
     */
    @EventListener
    @Override
    public void registry(RegistryServiceEvent event) {
        System.out.println("RegistryServiceEvent"+event.getClass());
    }

    /**
     * 版本修改事件
     * @param event
     */
    @Async
    @EventListener
    @Override
    public void version(VersionServiceEvent event) {
        System.out.println("VersionServiceEvent"+event.getClass());
    }

    /**
     * 分组修改事件
     * @param event
     */
    @Async
    @EventListener
    @Override
    public void group(GroupServiceEvent event) {
        System.out.println("GroupServiceEvent"+event.getClass());
    }
}
